<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>智能停车场管理系统-登录页面</title>
    <style>
        body {
            font-family: 'Microsoft YaHei', sans-serif;
            margin: 0;
            padding: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;

            background-color: white;
            overflow-x: hidden;
        }
        .container {
            width: 90%;
            max-width: 600px;
            margin: auto;
            text-align: center;
        }
        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            width: 100%;

            background-color: #007bff;
            padding: 15px 20px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            position: fixed;
            top: 0;
            left: 0;
            z-index: 1000;
        }
        .header img {
            height: 150px;
        }
        .header .welcome {
            margin-left: 10px;
            font-size: 3.5em;
            color: white;
            font-family: '宋体', sans-serif;
            font-weight: bold;
        }
        .header .login-link {
            margin-right: 10px;
            font-size: 1.0em;
            color: white;
            font-family: 'Microsoft YaHei', sans-serif;
            text-decoration: none;
        }
        .header .login-link:hover {
            color: #00008b;
            text-decoration: underline;
        }
        .content {
            margin-top: 80px;
            padding: 20px;
            background-color: #ffffff;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            text-align: left;
        }
        .form-group {
            margin-bottom: 20px;
        }
        .form-group label {
            display: block;
            margin-bottom: 5px;
            color: #000000;
            font-size: 1.2em;
        }
        .form-group input {
            width: calc(100% - 24px);
            padding: 12px 12px;
            box-sizing: border-box;
            border: none;
            border-radius: 5px;
            background-color: #f9f9f9;
            font-size: 1.2em;
        }
        .register-btn {
            width: calc(100% - 44px);
            padding: 12px 22px;
            background-color: #007bff;
            color: #ffffff;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 1.2em;
        }
        .register-btn:hover {
            background-color: #0056b3;
        }
        .success-message {
            margin-top: 20px;
            color: green;
            font-weight: bold;
            display: none;
        }
    </style>
</head>
<body>
<div id="app" class="container">
    <div class="header">
        <div style="display: flex; align-items: center;">
            <img src="images/logo2.png" alt="Logo">
            <div class="welcome">智能停车场管理系统欢迎登录！</div>
        </div>
        <a href="register.html" class="login-link" style="margin-right: 20px;">没有帐号？点击注册！</a>
    </div>
    <div class="content">
        <form id="loginForm">
            <div class="form-group">
                <label for="username">用户账号</label>
                <input type="text" id="username" v-model="account" name="username" minlength="5" maxlength="20" required pattern="[a-zA-Z0-9_]{1,20}" oninput="validateInput(this)">
            </div>
            <div class="form-group">
                <label for="password">用户密码</label>
                <input type="password" id="password" v-model="pwd" name="password" minlength="5" maxlength="32" required pattern="[a-zA-Z0-9!@#$%^&*()_+=-]{1,32}" oninput="validateInput(this)">
            </div>

            <button type="button" class="register-btn" @click="doLoginSubmit" onclick="loginUser()">登录</button>
            <div class="success-message" id="successMessage">登录成功！</div>
        </form>
    </div>
</div>

<script src="layui/layui.js" type="text/javascript"></script>
<script src="js/vue.js" type="text/javascript"></script>
<script src="js/jquery-3.6.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
    let vm = new Vue({
        el:"#app",
        data:{
            account:"",
            pwd:""
        },
        methods:{
            doLoginSubmit() {
                const url = "http://localhost:8080/user/login";
                const params = { account: this.account, pwd: this.pwd };
                $.get(url,params,(res)=>{
                    if(res.code==500){
                        alert(res.msg);
                    }else{
                        //登录成功
                        //将res的用户信息存储到浏览器的缓存当中

                        localStorage.setItem("userAccount",res.data.userAccount);
                        localStorage.setItem("userTel",res.data.userTel);
                        //跳转到home.html
                        window.location.href = "WEB-INF/home.html";
                    }
                },"JSON");
            }
        }
    });
</script>
<!--<script>-->
<!--    function loginUser() {-->
<!--        // 这里通常会有验证用户输入的逻辑，比如检查用户名和密码-->
<!--        // 假设验证通过，我们直接显示成功消息并跳转-->
<!--        document.getElementById('successMessage').style.display = 'block';-->
<!--        setTimeout(function() {-->
<!--            window.location.href = 'WEB-INF/home.html';-->
<!--        }, 2000); // 2秒后跳转-->
<!--    }-->

<!--    function validateInput(input) {-->
<!--        // 这里是输入验证的逻辑，根据实际需求实现-->
<!--        // 例如，清除之前的错误信息-->
<!--        const errorElement = document.getElementById(input.id + 'Error');-->
<!--        errorElement.textContent = '';-->

<!--        // 其他验证逻辑...-->
<!--    }-->
<!--</script>-->
</body>
</html>